package com.googlecode.gwt_control.client;

import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler;
import com.google.gwt.user.client.ui.HTML;

/**
 *
 * @author Olafur Gauti Gudmundsson
 */
public abstract class LoadPanelSubmitCompleteHandler implements SubmitCompleteHandler {

    public void onSubmitComplete(SubmitCompleteEvent event) {
        ApplicationManager.controller().getApplicationView().decreaseLoadCounter();
        try {
            if ( event.getResults() != null && event.getResults().equals("ERROR") ) {
                ApplicationManager.controller().getApplicationView().setErrorMessage(new HTML("Ooops...could not communicate with server."));
            } else {
                submitComplete(event);
            }
        } finally {
            ApplicationManager.controller().getApplicationView().decreaseLoadCounter();
        }
    }

    public abstract void submitComplete( SubmitCompleteEvent event );
}
